package com.xx.happychatboot.middleware.netty.domain.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * websocket回调枚举
 */
@AllArgsConstructor
@Getter
public enum WebSocketCallBackEnums {
    LOGIN_CALL_BACK(1, "登录回调"),
    HEARTBEAT_CALL_BACK(2, "心跳检测回调"),
    ADD_FRIEND_REMIND(1001, "添加好友提醒"),
    READ_ADD_FRIEND_REMIND(1002, "已阅读添加好友提醒"),
    AGREE_ADD_FRIEND(1003,"同意添加好友"),
    ;

    private final Integer type;
    private final String desc;

    // 缓存
    private static Map<Integer, WebSocketTypeEnum> cache;

    static {
        cache = Arrays.stream(WebSocketTypeEnum.values()).collect(Collectors.toMap(WebSocketTypeEnum::getType, Function.identity()));
    }

    public static WebSocketTypeEnum of(Integer type) {
        return cache.get(type);
    }
}
